import api from 'api/device'
import * as types from './mutation_type'

export default {
  listHostgroup({ commit }) {
    return new Promise((resolve, reject) => {
      api.listHostgroup().then(response => {
        if (response.status != 200) {
          commit(types.FAILURE_LIST_HOSTGROUP)
        } else {
          commit(types.SUCCESS_LIST_HOSTGROUP, response.data)
        }
        resolve(response)
      }).catch(err => {
        commit(types.FAILURE_LIST_HOSTGROUP)
        reject(err)
      });
    });
  },

  addDevice( { commit } , groupid) {
    api.queryHostByGroupid(groupid).then(response => {
      if (response.status == 200) {
        commit(types.SUCCESS_ADD_DEVICE, response.data);
      }
    });
  }
}
